/* eslint-disable */

//第三方类库加载管理js，方便切换lib

var configLibs = {
  //////////////////////////Map及其插件////////////////////////
  openlayer: [
    "openlayer/ol/ol.css",
    "openlayer/ol/ol.js",
    "openlayer/ol-ext/ol-ext.css",
    "openlayer/ol-ext/ol-ext.min.js",
    "openlayer/ol-contextmenu/ol-contextmenu.css",
    "openlayer/ol-contextmenu/ol-contextmenu.iife.js",
    "openlayer/gaode/gd-img.js",
    "turf/turf.min.js",
    "jsts/jsts.min.js",
    "openlayer/layers/LayerCreator.js",
    "openlayer/layers/LayerManager.js",
    "openlayer/layers/MapUtil.js",
    "openlayer/layers/BkolDraw.js",
    "openlayer/proj4/proj4.js"
  ],
  //////////////////////////其他地图渲染相关库////////////////////////
  'terraformer': [
    "terraformer/terraformer-1.0.9.min.js",
    "terraformer/terraformer-wkt-parser-1.2.0.min.js",
  ],
  'kriging': [
    "kriging/kriging.min.js"
  ],
  'gifler': [
    "gifler/gifler.min.js"
  ],
  'jquery': [
    "jquery/jquery-3.6.0.min.js",
  ],
}




  //内部处理方法
  ; (function () {
    var r = new RegExp('(^|(.*?\\/))(include-lib.js)(\\?|$)'),
      s = document.getElementsByTagName('script'),
      targetScript
    for (var i = 0; i < s.length; i++) {
      var src = s[i].getAttribute('src')
      if (src) {
        var m = src.match(r)
        if (m) {
          targetScript = s[i]
          break
        }
      }
    }

    // cssExpr 用于判断资源是否是css
    var cssExpr = new RegExp('\\.css')

    function inputLibs(list, baseUrl) {
      if (list == null || list.length === 0) {
        return
      }

      for (var i = 0, len = list.length; i < len; i++) {
        var url = list[i]
        if (!url.startsWith("http") && !url.startsWith("//:")) {
          url = baseUrl + url
        }

        if (cssExpr.test(url)) {
          var css = '<link rel="stylesheet" href="' + url + '">'
          document.writeln(css)
        } else {
          var script = '<script type="text/javascript" src="' + url + '"><' + '/script>'
          document.writeln(script)
        }
      }
    }

    //加载类库资源文件
    function load() {
      var arrInclude = (targetScript.getAttribute('include') || '').split(',')
      var libpath = targetScript.getAttribute('libpath') || ''
      if (libpath.lastIndexOf('/') !== libpath.length - 1) {
        libpath += '/'
      }

      var keys = {}
      for (var i = 0, len = arrInclude.length; i < len; i++) {
        var key = arrInclude[i]

        if (keys[key]) {
          //规避重复引入lib
          continue
        }
        keys[key] = true

        inputLibs(configLibs[key], libpath)
      }
    }

    load()
  })()
